package org.moda.dsl.source.loader;

import org.moda.common.Either;

import java.io.*;
import java.nio.file.Path;

/**
 * 本地文件加载器
 */
public class LocalFileLoader implements Loader {
    private final File file;

    public LocalFileLoader(String filePath) {
        this.file = new File(filePath);
    }

    @Override
    public Either<Throwable, byte[]> load() {
        // 实现从本地文件读取数据的逻辑 , 使用缓冲流看是否能读取快一点
        try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(file))) {
            return Either.right(in.readAllBytes());
        } catch (Exception e) {
            return Either.left(e);
        }
    }
}